const state = {
  messages: [],
  rentAuditNotifications: []
}

const mutations = {
  ADD_MESSAGE: (state, payload) => {
    state.messages.push(payload)
  },
  ADD_RENT_AUDIT_NOTIFICATION: (state, payload) => {
    state.rentAuditNotifications.push(payload)
  },
   REMOVE_NOTIFICATION(state, auditId) {
    state.rentAuditNotifications = state.rentAuditNotifications.filter(
      item => item.auditId !== auditId
    )
  }
}

const actions = {
  handleWebSocketMessage({ commit }, msg) {
    // 通用消息处理
    commit('ADD_MESSAGE', {
      ...msg,
      receivedAt: Date.now()
    })

    // 特定业务处理
    if (msg.type === 'RentAdjustAudit') {
      commit('ADD_RENT_AUDIT_NOTIFICATION', msg.content)
      console.log('已存储租金审批更新', msg.content)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}